<%@page import="java.util.List,com.crm.entity.Sources"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link href="<%=application.getContextPath()%>/css/css-crm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-1.7.2.min.js"></script>
<script language="javaScript" src="<%=application.getContextPath()%>/js/jquery-ui-1.8.20.custom.min.js"></script>

<script language="JavaScript" src="<%=application.getContextPath()%>/js/gen_validatorv4.js" type="text/javascript" ></script>

<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-1.6.min.js"></script>	
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-ui-1.8.17.custom.min.js"></script>	
<link rel="stylesheet" href="<%=application.getContextPath()%>/css/jquery-ui-1.8.17.custom.css"/>

<script language="JavaScript" src="<%=application.getContextPath()%>/js/gen_validatorv4.js" type="text/javascript" ></script>
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.js"></script>	
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.min.js"></script>	

<style >
.ui-dialog {
	
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	
}
	#bulletinDialog title{
	font-family:Arial, Helvetica, sans-serif;
	font-size:14px;
	font-weight:bold;
	}

</style>
</head>

<body>
<div id="main">

  <!-- <div id="header"></div> -->
   <%@ include file="common/header.jsp" %>
  <%@ include file="common/submenu.jsp" %>

  <div id="content">
    <div id="resultMsg" class="result_msg" >
    <% 
    	if(request.getAttribute("savesrc")!=null){
    		out.println(request.getAttribute("savesrc"));
    	}
    	
    %>
    </div>
       <div id="clisname"  style="display: none; text-align: center; padding-top:5px;" >
  <label style="font-family:Arial; font-size: 12px; font-weight: bold ; align: center; color: red;">The Source Name is Already Exists!Please Choose Another</label>
    </div>
 <div id="saveSource">
	<form id="form1" name="form1" method="post" action="<%= application.getContextPath()%>/source/save.do">

    <div id="work-area2">
    
      <div class="heading">Sources</div>
	  
      <div class="boxIFS">
        
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="left">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td width="19%" align="left">Name</td>
              <td width="30%" align="left" valign="middle">
           <%-- 
              <% if(request.getAttribute("sources-List")==null)
              {%>   --%>        
                 <input name="name" type="text" class="form"  onblur="javascript:sourceNameCheck();"   id="nameid" />
            <%--      <%}else{ 
                 List<Sources> ls=(List<Sources>)request.getAttribute("sources-List");%>
                 <select name="soName1" id="soName2">
                 <option value="Please Select">Please Select</option>
                 <% for(int i=0;i<ls.size();i++){
                 System.out.println("I Value Is:"+i);
                 %>
                 <option value="<%=ls.get(i).getSourceName()%>"><%=ls.get(i).getSourceName()%></option>
                 <% }%>
                 </select>
                 <%} %> --%>
                 </td>
              <td width="13%" align="left" valign="middle">Website</td>
              <td width="22%" align="left" valign="middle">
              <input name="website" type="text" class="form" id="websiteid" /></td>
              <td width="1%" align="left" valign="middle">&nbsp;</td>
              <td width="15%" align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td align="left">Email</td>
              <td align="left" valign="middle"><label>
                <input name="email" type="text" class="form-lowercase" id="emailid" />
                </label>              </td>
              <td align="left" valign="middle">Fax</td>
              <td align="left" valign="middle"><label>
                <input name="fax" type="text" class="form" id="faxid" />
                </label>              </td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td align="left">Phone Number</td>
              <td align="left" valign="middle"><label>
                <input name="phone" type="text" class="form" id="phoneid" />
                </label>              </td>
              <td align="left" valign="middle">Country</td>
              <td align="left" valign="middle"><label></label>    
              <select name="country" class="form" id="countryid">
				<option value="INDIA">INDIA</option>
				<option value="USA">USA</option>
				</select>    
                  </td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td align="left">Address</td>
              <td align="left" valign="top">
              <textarea name="address" class="form-textarea" id="addressid"></textarea></td>
              <td align="left" valign="top">Cell</td>
              <td align="left" valign="top">
              <input name="cell" type="text" class="form" id="cellid" /></td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="2" align="left" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="10%"><label>
                    <input type="checkbox" name="assupplier" id="assupplierid" />
                  </label></td>
                  <td width="90%">Source as Supplier</td>
                </tr>
              </table>                <label></label></td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr>
          </table>
     
      </div>
	  
	  <div class="boxtable" id="supplierDiv" style="display:none">
	  <table>
	   <tr>
	  <td>
        <table  id="userTable" width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#C5E4EB">
          <tr>
            <td width="36" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"  style="background-repeat:repeat-x">S.No </td>
            <td width="138" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Contact Person</td>
            <td width="162" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"  style="background-repeat:repeat-x bgcolor="#FFFFFF">Phone</td>
            <td width="186" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Email</td>
          </tr>
          <tr>
            <td align="center" bgcolor="#FFFFFF">1</td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="cperson1" type="text" size="5" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="phone1" type="text" size="5" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="email1" class="email" type="text" size="5" /></td>
          </tr>
          
          <input name="rowcount" type="hidden" id="rowcountid" value="1"/>
        </table>
                </td>
        </tr>
        <tr>
                <td align="left" valign="top"><div class="buttonleft"><a href="javascript:addRow('userTable')" >Add Row</a></div> 
                                   <div class="buttonleft"><a href="javascript:deleteRow('userTable')" >Delete Row</a></div>
                                    
                   </td>
              </tr>
              <tr>
                <td> 
	  				  </td>
              </tr>
              </table>
	  </div>
	  <div class="buttton-main">
	    <input type="reset" value="Clear" class="button"/>
	    <div class="button"><a href="<%=application.getContextPath()%>/source/delete.do">Delete</a></div>
	   <input type="button" class="button" value="Edit" onclick="javascript: retriveSource()" />
	     <input type="submit" class="button" value="Save" onclick="javascript:return validate();"/>
	    </div>
    </div>
	
    </form>
   <div id="bulletinDialog"  title="Source  Edit  Here" style="display: none;">
                  <div id="clientSearchBox">
           <form action="<%= application.getContextPath()%>/source/search.do" method="post">   
           <table >
           <tr><td>&nbsp;</td></tr> 
           <tr><td align="left"><select  name="soName"  id="srcId">
                   </select></td>
                   <td align="right"> <input class="button" type="submit" id="ok" onclick="javascript:return Editvalidate();" value="Edit"/></td></tr>
                    </table>
                    </form>
                    </div>
                    
        </div>
    </div>
    </div>
    

    
   

  


  <div id="footer"></div>  
</div>
</body>

</html>
<script type="text/javascript">
function validate(){
	var name=$("#nameid").val();
	var website=$("#websiteid").val();
	var email=$("#emailid").val();
	var fax=$("#faxid").val();
	var phone=$("#phoneid").val();
	var country=$("#countryid").val();
	var address=$("#addressid").val();
	var cell=$("#cellid").val();
	
	if(name==null || name==""){
		jAlert("Please Enter Source Name");
		$("#nameid").focus();
		return false;
	}
	if(website==null || website==""){
		jAlert("Please Enter Website");
		$("#websiteid").focus();
		return false;
	}
	var emailFormat = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	 if(emailFormat.test(email) == false) {
	 
	      jAlert('Invalid Email Address');
	      $("#email").focus();
	      return false;
	   }
	if(fax==null || fax==""){
		jAlert("Please Enter FAX Number");
		$("#faxid").focus();
		return false;
	}
	if(phone==null || phone==""){
		jAlert("Please Enter Phone Number");
		$("#phoneid").focus();
		return false;
	}
	if(country==null || country==""){
		jAlert("Please Enter Country");
		$("#countryid").focus();
		return false;
	}
	if(address==null || address==""){
		jAlert("Please Enter Address");
		$("#addressid").focus();
		return false;
	}
	if(cell==null || cell==""){
		jAlert("Please Enter Cell Number");
		$("#cellid").focus();
		return false;
	}
	

	
}
function addRow(userTable) {
	 
    var table = document.getElementById(userTable);
		var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	
	table.setAttribute("bgColor", "#C5E4EB");
    var cell1 = row.insertCell(0);
    cell1.innerHTML = rowCount ;
   	cell1.setAttribute("bgColor","#FFFFFF");
   	cell1.setAttribute("align","center");
    
   	
    var cell2 = row.insertCell(1);
    cell2.setAttribute("bgColor","#FFFFFF");
    var element2 = document.createElement("input");
	element2.type = "text";
	element2.name="cperson"+rowCount;
	element2.id="cperson"+rowCount;
	element2.className="user";
	element2.size="15";
    cell2.appendChild(element2);
    
    
    /* var cell3 = row.insertCell(2);
    cell3.setAttribute("bgColor","#FFFFFF");
    cell3.innerHTML='<select name="division'+rowCount+'" class="form1" id="division'+rowCount+'" style="border: 0px;">'
		+' <option value="">Please Select</option>'
    +'</select>'; */
	
	var cell3 = row.insertCell(2);
	cell3.setAttribute("bgColor","#FFFFFF");
	 var element3 = document.createElement("input");
		element3.type = "text";
		element3.name="phone"+rowCount;
		element3.id="phone"+rowCount;
		element3.className="user";
		element3.size="15";
        cell3.appendChild(element3);
	
	
	 var cell4 = row.insertCell(3);
	//cell5.innerHTML='<input name="org[]"  id="org"'+rowcount+' type="text" class="tablebox-form" size="8"  />';
	 cell4.setAttribute("bgColor","#FFFFFF");
	 var element4 = document.createElement("input");
		element4.type = "text";
		element4.name="email"+rowCount;
		element4.id="email"+rowCount;
		element4.className="email";
		element4.size="15";
        cell4.appendChild(element4);
		
        document.getElementById('rowcountid').value=rowCount;

        $("#cperson"+rowCount).focus();
}

function deleteRow(userTable) {
	var tbl = document.getElementById(userTable);
	var lastRow = tbl.rows.length;
	if (lastRow > 2) tbl.deleteRow(lastRow - 1);
	var table = document.getElementById(userTable);
	var rowCount = table.rows.length;
	/* alert(rowCount); */
	document.getElementById('rowcountid').value=rowCount-1;
}
</script>
<script  type="text/javascript">


function sourceNameCheck(){
	var busName=$("#nameid").val();
	//alert("csname is clicked");
	var data="name="+busName;
	if(busName!=null && busName!=""){
		$.ajax({
			url:" <%=application.getContextPath()%>/source/SourceNameCheck.do",
			mimetype: "text/plain",
			method: "post",
			data: data,
			cache:false,
			success: function(res){
				//alert("Response Is :"+res);
				if(res=="true"){
					$("#clisname").hide();
				}else{
					//jAlert("Client ShortName Already Exists \n Please Enter Another.");
					$("#clisname").show();
					$("#nameid").focus();
				}
			}
		
		});
	}
}


function retriveSource(){
	
	$.ajax({
		url:"<%=application.getContextPath()%>/source/edit.do",
		mimetype: "text/plain",
		cache:false,
		success: function(res){
			var e2=document.getElementById('srcId');
			$('#srcId')
		    .find('option')
		    .remove()
		    .end()
		   	;
			var temp=res.split(",");
			var o=document.createElement('option');
			o.value="";
			o.text="Please Select";
			e2.options.add(o);
			if(temp != null){
				for(var i=0;i<temp.length-1;i++){
					var o=document.createElement('option');
					o.value=temp[i];
					o.text=temp[i];
					e2.options.add(o);
				}
			}
			
			
		}

	});
	
	var $dialog = $('#bulletinDialog').dialog({
		         
                autoOpen: false,
                modal: true,
                width: 400,
                height: 150
              				
            });
            $dialog.dialog('open');

}


function Editvalidate(){
	var srcname=$("#srcId").val();
	if(srcname==null || srcname==""){
		//jAlert("srcnameis"+srcname);
		jAlert("Please Select One Source");
		$("#srcId").focus();
		return false;
	}
	else
		{
		return true;
		}
}
$("#assupplierid").click(function(){
	$("#supplierDiv").toggle();
});

</script>
